#include <iostream>
#include <cstdio>
#include <unistd.h>
#include <sys/wait.h>


const std::string myenv = "HELLO=AAAAAAAAAAAAAAAAAAAA";
int main()
{
    putenv((char*)myenv.c_str());
    pid_t id = fork();
    if(id == 0)
    {
        char* const argv[] = {
            (char*)"ls",
            (char*)"--color",
            (char*)"-a",
            (char*)"-l",
            nullptr
        };
        // 自己的环境变量表
        char* const env[]=
        {
            (char*)"HELLO=world",
            (char*)"HELLO1=world1",
            (char*)"HELLO2=world2",
            (char*)"HELLO3=world3"
        };
        (void)env;

        //execv("/bin/ls", argv);
        execvp("ls", argv);
        //execlp("ls", "ls", "-l", "-a", nullptr);

        // child
        //sleep(3);
        //execl("/bin/ls", "ls", "-l", "-a", nullptr);
        exit(1);
    }
    // father
    pid_t rid = waitpid(id, nullptr, 0);
    if(rid > 0)
    {
        printf("等待子进程成功\n");

    }
    
    return 0;
}
